/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.autoupdate; import java.util.*; import javax.swing.DefaultListModel; import javax.swing.JButton; import org.openide.util.NbBundle; import org.openide.TopManager; import org.openide.NotifyDescriptor; /** * * @author phrebejk * @version */ public class ResultsPanel extends javax.swing.JPanel { private static final ResourceBundle bundle = NbBundle.getBundle( ResultsPanel.class ); private DefaultListModel resultsListModel; private Wizard.Validator validator; private Updates updates; private int modulesOK; private java.awt.Dimension preferredDimension = null; static final long serialVersionUID =-6053101371836354161L; /** Creates new form ResultsPanel */ public ResultsPanel( Wizard.Validator validator ) { initComponents (); this.updates = updates; this.validator = validator; resultsListModel = new DefaultListModel(); resultsList.setSelectionMode( javax.swing.ListSelectionModel.SINGLE_SELECTION ); resultsList.setModel( resultsListModel ); resultsList.setCellRenderer( new ResultListCellRenderer() ); resultsList.getSelectionModel().addListSelectionListener( new javax.swing.event.ListSelectionListener() { public void valueChanged( javax.swing.event.ListSelectionEvent evt ) { selectionChange(); } } ); selectionChange(); //checkValidity(); } private java.awt.Dimension getButtonPrefferedSize() { if ( preferredDimension == null ) { preferredDimension = new java.awt.Dimension(); javax.swing.JButton tmpButton = new javax.swing.JButton(); preferredDimension.height = acceptButton.getPreferredSize().height; int w1, w2, w3, w4; tmpButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton1.text.download")); w1 = tmpButton.getPreferredSize().width; tmpButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton1.text")); w2 = tmpButton.getPreferredSize().width; tmpButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton2.text.download")); w3 = tmpButton.getPreferredSize().width; tmpButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton2.text")); w4 = tmpButton.getPreferredSize().width; preferredDimension.width = Math.max( Math.max( w1, w2 ), Math.max( w3, w4 ) ); } return preferredDimension; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents jTextArea1 = new javax.swing.JTextArea (); infoLabel = new javax.swing.JLabel (); jPanel3 = new javax.swing.JPanel (); jScrollPane2 = new javax.swing.JScrollPane (); resultsList = new javax.swing.JList (); acceptButton = new javax.swing.JButton() { public java.awt.Dimension getMinimumSize() { return getButtonPrefferedSize(); } }; rejectButton = new javax.swing.JButton() { public java.awt.Dimension getMinimumSize() { return getButtonPrefferedSize(); } }; viewButton = new javax.swing.JButton (); setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints1; setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(16, 8, 16, 8))); jTextArea1.setLineWrap (true); jTextArea1.setWrapStyleWord (true); jTextArea1.setBackground ((java.awt.Color) javax.swing.UIManager.getDefaults ().get ("Label.background")); // NOI18N jTextArea1.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jTextArea1.text")); jTextArea1.setEditable (false); jTextArea1.setFont (new java.awt.Font ("Dialog", 0, 12)); // NOI18N gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 0.2; add (jTextArea1, gridBagConstraints1); infoLabel.setFont (new java.awt.Font ("Dialog", 1, 12)); // NOI18N gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets (0, 0, 6, 0); gridBagConstraints1.weightx = 1.0; add (infoLabel, gridBagConstraints1); jPanel3.setLayout (new java.awt.GridBagLayout ()); java.awt.GridBagConstraints gridBagConstraints2; jScrollPane2.setViewportView (resultsList); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridheight = 0; gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints2.insets = new java.awt.Insets (0, 0, 0, 8); gridBagConstraints2.weightx = 1.0; gridBagConstraints2.weighty = 1.0; jPanel3.add (jScrollPane2, gridBagConstraints2); acceptButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton1.text")); acceptButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { acceptButtonActionPerformed (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridwidth = 0; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (0, 0, 8, 0); gridBagConstraints2.anchor = java.awt.GridBagConstraints.SOUTH; jPanel3.add (acceptButton, gridBagConstraints2); rejectButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton2.text")); rejectButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { rejectButtonActionPerformed (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridx = 1; gridBagConstraints2.gridy = 1; gridBagConstraints2.gridwidth = 0; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.insets = new java.awt.Insets (0, 0, 8, 0); gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST; jPanel3.add (rejectButton, gridBagConstraints2); viewButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.viewButton.text")); viewButton.addActionListener (new java.awt.event.ActionListener () { public void actionPerformed (java.awt.event.ActionEvent evt) { viewButtonActionPerformed (evt); } } ); gridBagConstraints2 = new java.awt.GridBagConstraints (); gridBagConstraints2.gridwidth = 0; gridBagConstraints2.gridheight = 0; gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTH; jPanel3.add (viewButton, gridBagConstraints2); gridBagConstraints1 = new java.awt.GridBagConstraints (); gridBagConstraints1.gridwidth = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 0.8; add (jPanel3, gridBagConstraints1); }//GEN-END:initComponents private void viewButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewButtonActionPerformed CertDialog.viewCert( getListSelection().getCerts() ); }//GEN-LAST:event_viewButtonActionPerformed private void rejectButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rejectButtonActionPerformed if ( getListSelection().getSecurity() == SignVerifier.NOT_SIGNED ) { getListSelection().setInstallApproved( false ); checkValidity(); } else { switch ( RejectDialog.showDialog( bundle.getString( "MSG_reject.Message" ), NotifyDescriptor.QUESTION_MESSAGE ) ) { case RejectDialog.FOR_MODULE: getListSelection().setInstallApproved( false ); checkValidity(); break; case RejectDialog.FOR_NOW: setApproved4All( getListSelection().getCerts(), false, -1 ); checkValidity(); break; case RejectDialog.FOREVER: setApproved4All( getListSelection().getCerts(), false, SignVerifier.SIGNED ); checkValidity(); try { SignVerifier.removeCertificates( getListSelection().getCerts() ); } catch ( java.security.cert.CertificateException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } catch ( java.security.KeyStoreException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } catch ( java.io.IOException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } catch ( java.security.NoSuchAlgorithmException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } break; } } resultsList.invalidate(); resultsList.repaint(); selectionChange(); }//GEN-LAST:event_rejectButtonActionPerformed private void acceptButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed if ( getListSelection().getSecurity() == SignVerifier.NOT_SIGNED ) { NotifyDescriptor.Confirmation nd = new NotifyDescriptor.Confirmation( bundle.getString( "MSG_NotSignedConfirmation" ), bundle.getString( "CTL_NotSignedConfirmation" ), NotifyDescriptor.YES_NO_OPTION ); if ( TopManager.getDefault().notify( nd ).equals( NotifyDescriptor.YES_OPTION ) ) { getListSelection().setInstallApproved( true ); checkValidity(); } } else { int accValue = CertDialog.acceptCert( getListSelection().getCerts() ); switch ( accValue ) { case CertDialog.FOR_MODULE: getListSelection().setInstallApproved( true ); checkValidity(); break; case CertDialog.FOR_NOW: setApproved4All( getListSelection().getCerts(), true, -1 ); checkValidity(); break; case CertDialog.FOREVER: setApproved4All( getListSelection().getCerts(), true, SignVerifier.TRUSTED ); checkValidity(); try { SignVerifier.addCertificates( getListSelection().getCerts() ); } catch ( java.security.cert.CertificateException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } catch ( java.security.KeyStoreException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } catch ( java.io.IOException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } catch ( java.security.NoSuchAlgorithmException e ) { if ( Boolean.getBoolean ("netbeans.debug.exceptions") ) // NOI18N System.out.println("Can't add certificate to keystore " + e ); // NOI18N } break; default: return; } } resultsList.invalidate(); resultsList.repaint(); selectionChange(); }//GEN-LAST:event_acceptButtonActionPerformed /** Utility function approves installing of all modules signed * by given Collection of certs */ private void setApproved4All( Collection certs, boolean approved, int security ) { if ( certs == null ) { return; } Enumeration modules = resultsListModel.elements(); while( modules.hasMoreElements() ) { ModuleUpdate mu = (ModuleUpdate)modules.nextElement(); if ( mu.getCerts() != null && certs.containsAll( mu.getCerts() ) ) { mu.setInstallApproved( approved ); if ( security == SignVerifier.TRUSTED || security == SignVerifier.SIGNED ) { mu.setSecurity( security ); } } } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTextArea jTextArea1; private javax.swing.JLabel infoLabel; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JList resultsList; private javax.swing.JButton acceptButton; private javax.swing.JButton rejectButton; private javax.swing.JButton viewButton; // End of variables declaration//GEN-END:variables int generateResults( Updates updates ) { this.updates = updates; modulesOK = 0; resultsListModel.clear(); Collection modules = updates.getModules(); Iterator it = modules.iterator(); while( it.hasNext() ) { ModuleUpdate mu = (ModuleUpdate)it.next(); if ( mu.isSelected() ) { resultsListModel.addElement( mu ); if ( mu.isDownloadOK() ) modulesOK ++; } } checkValidity(); return modulesOK; } /** Called when the selection in selectedList or explorerView changes */ private void selectionChange() { ModuleUpdate mu = getListSelection(); // Enable / Disable Accept button if ( mu != null && !mu.isInstallApproved() && ( mu.getSecurity() == SignVerifier.NOT_SIGNED || mu.getSecurity() == SignVerifier.SIGNED || mu.getSecurity() == SignVerifier.TRUSTED ) ) { acceptButton.setEnabled( true ); if ( mu.getSecurity() == SignVerifier.NOT_SIGNED ) { acceptButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton1.text.download")); } else { acceptButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton1.text")); } } else { acceptButton.setEnabled( false ); } // Enable disable Reject Button if ( mu != null && mu.isInstallApproved() && ( mu.getSecurity() == SignVerifier.NOT_SIGNED || mu.getSecurity() == SignVerifier.SIGNED || mu.getSecurity() == SignVerifier.TRUSTED ) ) { rejectButton.setEnabled( true ); if ( mu.getSecurity() == SignVerifier.NOT_SIGNED ) { rejectButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton2.text.download")); } else { rejectButton.setText (org.openide.util.NbBundle.getBundle(ResultsPanel.class).getString("ResultsPanel.jButton2.text")); } } else { rejectButton.setEnabled( false ); } // Enable/Disable view button if ( mu != null && ( mu.getSecurity() == SignVerifier.SIGNED || mu.getSecurity() == SignVerifier.TRUSTED ) ) { viewButton.setEnabled( true ); } else { viewButton.setEnabled( false ); } } /** Gets the ModuleUpdate selected in the list */ private ModuleUpdate getListSelection() { int index = resultsList.getMinSelectionIndex(); if ( index < 0 ) return null; return (ModuleUpdate) resultsListModel.get( index ); } /** Checks wther there exists at least one update with approved install * if so enables finish button */ private void checkValidity() { boolean valid = false; int okCount = 0; Collection modules = updates.getModules(); Iterator it = modules.iterator(); while( it.hasNext() ) { ModuleUpdate mu = (ModuleUpdate)it.next(); if ( mu.isInstallApproved() ) { valid = true; okCount++; } } validator.setValid( valid ); infoLabel.setText( java.text.MessageFormat.format( bundle.getString("ResultsPanel.infoLabel.text"), new Object[] { new Integer(okCount), new Integer( resultsListModel.size() ) } ) ); } } /* * Log * 10 Gandalf 1.9 1/12/00 Petr Hrebejk i18n * 9 Gandalf 1.8 1/3/00 Petr Hrebejk Various bug fixes - * 5097, 5098, 5110, 5099, 5108 * 8 Gandalf 1.7 12/20/99 Petr Hrebejk Autocheck & security * finished * 7 Gandalf 1.6 12/16/99 Petr Hrebejk Sign checking added * 6 Gandalf 1.5 12/1/99 Petr Hrebejk Checkin signatures of * NBM files & automatic autoupdate check added * 5 Gandalf 1.4 11/27/99 Patrik Knakal * 4 Gandalf 1.3 10/22/99 Ian Formanek NO SEMANTIC CHANGE - Sun * Microsystems Copyright in File Comment * 3 Gandalf 1.2 10/11/99 Petr Hrebejk Last minute fixes * 2 Gandalf 1.1 10/11/99 Petr Hrebejk Version before Beta 5 * 1 Gandalf 1.0 10/10/99 Petr Hrebejk * $ */